package com.sync.syncmasterdata.product.repository.u8;

import com.sync.syncmasterdata.product.entity.u8.InvEx;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.Map;

/**
 * U8 产品档案 自定义字段表
 */
@Repository
public interface InvExRepository extends JpaRepository<InvEx, String> {

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(nativeQuery = true, value="update Inventory_extradefine set cidefine2=?2 ,cidefine3=?3,cidefine4=?4,cidefine5=?5 where cInvCode=?1")
    void updateInvEx(String cInvCode,String cidefine2,String cidefine3,String cidefine4,String cidefine5);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(nativeQuery = true, value="update UFDATA_170_2020..Inventory_extradefine set cidefine2=?2 ,cidefine3=?3,cidefine4=?4,cidefine5=?5,cidefine6=?6 where cInvCode=?1")
    void save170(String cInvCode,String cidefine2,String cidefine3,String cidefine4,String cidefine5,String cidefine6);

    /**
     * 获取U8 产品自定义扩展项目字段
     * (接口没有该功能)
     */
    @Query(nativeQuery = true, value = "select top 1 cidefine2 ,cidefine3,cidefine4,cidefine5 from Inventory_extradefine where cInvCode=:cInvCode")
    Map<String, String> getProductExByCode(@Param(value = "cInvCode") String cInvCode);

}
